import { AllHTMLAttributes, createElement, type FC } from 'react';
import classNames from 'classnames';

import { listHeaderDefaultProps } from './defaultProps';
import type { ListHeaderOptions } from './type';

export interface ListHeaderProps extends ListHeaderOptions, Omit<AllHTMLAttributes<HTMLElement>, 'as'> {}

const ListHeader: FC<ListHeaderProps> = (props) => {
  const { className, as, children, forwardedRef, ...listHeaderProps } = props;

  return createElement(
    as!,
    { ref: forwardedRef, className: classNames('header', className), ...listHeaderProps },
    children,
  );
};

ListHeader.displayName = 'ListHeader';
ListHeader.defaultProps = listHeaderDefaultProps;

export default ListHeader;
